package lg.minecraft.plugin.pokedex.command;

import com.cobblemon.mod.common.api.pokedex.*;
import com.cobblemon.mod.common.api.pokedex.def.PokedexDef;
import com.cobblemon.mod.common.api.pokedex.entry.PokedexCosmeticVariation;
import com.cobblemon.mod.common.api.pokedex.entry.PokedexEntry;
import com.cobblemon.mod.common.api.pokedex.entry.PokedexForm;
import com.cobblemon.mod.common.util.PlayerExtensionsKt;
import lg.minecraft.plugin.library.command.CommandContext;
import lg.minecraft.plugin.library.command.CommandType;
import lg.minecraft.plugin.library.command.SubCommand;
import net.minecraft.class_3222;
import org.bukkit.entity.Player;

/**
 * @author langle__
 * @version 1.0
 */
public class SubGrantCommand extends SubCommand {

    public SubGrantCommand() {
        super("grant", "g");
    }

    @Override
    public String getPermission() {
        return "LGPokedex.command.grant";
    }

    @Override
    public String getDescription() {
        return "给予图鉴";
    }

    @Override
    public CommandType getCommandType() {
        return CommandType.PLAYER;
    }

    @Override
    public void onCommand(CommandContext context) {
        Player player = context.getPlayer();
        class_3222 nmsPlayer = PlayerExtensionsKt.getPlayer(player.getUniqueId());
        if (nmsPlayer == null) return;
        PokedexManager dexManager = PlayerExtensionsKt.pokedex(nmsPlayer);
        for (PokedexDef pokedexDef : Dexes.INSTANCE.getDexEntryMap().values()) {
            for (PokedexEntry dexEntry : pokedexDef.getEntries()) {
                SpeciesDexRecord speciesRecord = dexManager.getOrCreateSpeciesRecord(dexEntry.getSpeciesId());
                for (PokedexForm form : dexEntry.getForms()) {
                    for (String unlockForm : form.getUnlockForms()) {
                        FormDexRecord formRecord = speciesRecord.getOrCreateFormRecord(unlockForm);
                        formRecord.setKnowledgeProgress(PokedexEntryProgress.CAUGHT);
                        formRecord.addAllShinyStatesAndGenders();
                    }
                }
                for (PokedexCosmeticVariation variation : dexEntry.getVariations()) {
                    speciesRecord.addAspects(variation.getAspects());
                }
            }
        }
        player.sendMessage("[§6§lLG§ePokedex§f] 已经给予全图鉴");
    }

}
